<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

class CoreRequestParser extends CoreObject {
	
	//constructor
	function CoreRequestParser() {
		parent::CoreObject();
	}
	
	//methods
	function pares() {
		if( strpos(SYS_RT_REQUEST_URI, '?') == false ) {
			$request_uri = SYS_RT_REQUEST_URI;
		} else {
			$request_uri = substr(SYS_RT_REQUEST_URI, 0, strpos(SYS_RT_REQUEST_URI, '?'));
		}
		//filter
		$request_uri = ereg_replace("(\/{2,})", "/", $request_uri);
		$request_uri = ereg_replace("(^\/)", "", $request_uri);
		//friendly
		if( CONFIG_URL_DIRECTORY == true ) {
			//
		} else {
			$request_uri = str_replace('~', '/', $request_uri);
		}
		//
		//if( util_not_null($request_uri)
		//do not use the function util_xxx
		if( strlen($request_uri) > 0 && (substr($request_uri, 0, strlen('index.php')) != 'index.php') ) {
			$link_result = util_parse_link($request_uri);
			$request_type = $link_result['type'];
			$request_link = $link_result['link'];
		} else {
			$request_type = '';
			$request_link = '';
		}
		$request_param = $_SERVER['QUERY_STRING'];
		//$request_redirect = substr($_SERVER['REDIRECT_URL'], strlen(CONFIG_URL_PREFIX));
		//////////////////////////////////////////////////////////////////////////////////////////////////////////////
		$request_link_class = '';
		$request_link_subclass = '';
		$request_link_param = array();
		$request_link_parse = str_replace(CONFIG_URL_SUFFIX, '', $request_link);
		if( strpos($request_link_parse, '?') == false ) {
			$request_link_parse_array = explode('/', $request_link_parse);
		} else {
			$request_link_parse_array = explode('/', substr($request_link_parse, 0, strpos($request_link_parse, '?')));
		}
		$request_link_class = $request_link_parse_array['0'];
		$request_link_subclass = $request_link_parse_array['1'];
		if( sizeof($request_link_parse_array) > 2 ) {
			$request_link_param = array_slice($request_link_parse_array, 2);
		}
		$id = trim(strtolower(util_get_param($_REQUEST, 'id')));
		$action = trim(strtolower(util_get_param($_REQUEST, 'action')));
		$operation = trim(strtolower(util_get_param($_REQUEST, 'op')));
		$page = trim(strtolower(util_get_param($_GET, 'page')));
		if( !is_numeric($page) ) {
			$page = 1;
		}
		//assign
		$this->request = array();
		$this->request_uri = $request_uri;
		$this->request_type = $request_type;
		$this->request_link = $request_link;
		$this->request_param = $request_param;
		$this->request_link_class = $request_link_class;
		$this->request_link_subclass = $request_link_subclass;
		$this->request_link_param = $request_link_param;
		$this->request['id'] = $id;
		$this->request['action'] = $action;
		$this->request['operation'] = $operation;
		$this->request['page'] = $page;
		$this->request['action'] = $action;
		$this->request['action'] = $action;
	}
	
	function query() {
		
	}
	
	//
	function get() {
		
	}
	
	function post() {
		
	}
	
	function cook() {
		
	}
	
	function sess() {
		
	}
	
	function serv() {
		
	}
}
//
?>